package edu.ustb.service;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import edu.ustb.domain.Goods;
import edu.ustb.mapper.GoodsMapper;
import edu.ustb.utils.MybatisUtil;

public class GoodsServiceImpl implements GoodsService {

	@Override
	public List<Goods> findGoodsList(String pageNum) {
		//try {
		//	GoodsMapper goodsMapper = MybatisUtil.getMapper(GoodsMapper.class);
		//	PageHelper.startPage(Integer.parseInt(pageNum),6);
		//	List<Goods> goodsList = goodsMapper.findAll();
		//	MybatisUtil.close();
		//	System.out.println(goodsList);
		//	return goodsList;
		//} catch (Exception e) {
		//	e.printStackTrace();
		//	return null;
		//}
		return null;
	}

	@Override
	public Goods findGoodsByGoodsId(String goodsId) {
		try {
			GoodsMapper goodsMapper = MybatisUtil.getMapper(GoodsMapper.class);
			Goods goods = goodsMapper.findGoodsByGoodsId(goodsId);
			MybatisUtil.close();
			//System.out.println(goods);
			return goods;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public PageInfo<Goods> getPageGoodsBypageNum(int newPageNum, String target) {
		GoodsMapper mapper = MybatisUtil.getMapper(GoodsMapper.class);
		PageHelper.startPage(newPageNum, 6);
		List<Goods> goodsList = mapper.findAll(target);
		System.out.println(goodsList);
		PageInfo<Goods> pageInfo = new PageInfo<>(goodsList);
		return pageInfo;
	}

}
